#define _CRT_SECURE_NO_WARNINGS 1

9.https:leetcode - cn.com / problems / intersection - of - two - linked - lists / description /
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* getIntersectionNode(struct ListNode* headA, struct ListNode* headB) {
    int lenA = 0, lenB = 0;
    struct ListNode* curA = headA, * curB = headB;
    while (curA) {
        ++lenA;
        curA = curA->next;
    }

    while (curB) {
        ++lenB;
        curB = curB->next;
    }

    int gap = abs(lenA - lenB);
    struct ListNode* longList = headA, * shortList = headB;
    if (lenA < lenB) {
        longList = headB;
        shortList = headA;
    }

    while (gap--) {
        longList = longList->next;
    }

    while (longList && shortList)
    {
        if (longList->val == shortList->val) {
            return longList;
        }
        else {
            longList = longList->next;
            shortList = shortList->next;
        }
    }

    return NULL;
}


https://leetcode-cn.com/problems/linked-list-cycle/description/
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
bool hasCycle(struct ListNode* head) {
    struct ListNode* slow = head;
    struct ListNode* fast = head;
    while (fast && fast->next)
    {
        slow = slow->next;
        fast = fast->next->next;

        if (slow == fast)
            return true;
    }

    return false;
}